<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=3,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>评论</title>
    <link href="../css/reset-html5.css" rel="stylesheet">
    <link href="../css/mui.min.css" rel="stylesheet">
    <link href="../css/wx-main.css?20161105" rel="stylesheet">
    <script src="../js/jquery-2.2.1.min.js"></script>
    <script src="../plugins/vue/vue.min.js"></script>
    <script src="../js/mui.min.js"></script>
</head>
<body class="body-bg" id="main">
<div>
    <header class="text-color1">
        <span class="left-btn text-color2" onclick="location.href='index.html'">
            返回
        </span>

    </header>


    <div class="mui-card" v-for="list in comment_list">
        <div class="mui-card-content">
            <div class="mui-card-content-inner text-color1">
                <span class="text-color3" v-text="list.phone"> </span>：<span v-text="list.content"></span>
                <p class="mui-text-right text-color3 mar-top" v-text="list.ctime | getLocalTime">
                    2016-11-15 16:54:30
                </p>
            </div>
        </div>
    </div>

    <div class="mar-top mar-btm text-color1 text-center" v-on:click="more()" v-show="comment_list.length>=20">点击加载更多</div>
</div>

</body>
<script src="../js/phone.js?123"></script>
<script src="layer_mobile/layer.js"></script>
<script>
    var pageNum = 1;
    var min_id;
    var comment_list=[];
    var vue =new Vue({
        el:'#main',
        data:{
            'comment_list':''
        },
        methods:{
            'show_comment':function(data){
                this.comment_list = data;
            },
            'more':function(){
                pageNum++;
                get_comment_list();
            }
        },
        ready:function(){

        }
    });

    get_comment_list();

    /**
     * 获取评论列表
     */
    function get_comment_list(){
        var data = {};
        data.page = pageNum;
        data.count = 20;
        data.id = min_id;
		var index = layer.open({type: 2,shadeClose:false});
        $.post('../index/index.php?m=Home&c=Index&a=getCommentList',data,function(res){
            if(res.code==200){
                min_id = res.data.id;
                for(var i in res.data.list){
                    comment_list.push(res.data.list[i]);
                }
                vue.show_comment(comment_list);
            }else if(res.code==0){
                location.href = 'index.html?url='+ window.location.href;
            }else{
                alert(res.message);
            }
            layer.close(index);
        },'json');
    }


    Date.prototype.Format = function(format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                        ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    };

    //将UTC格式转为正常的日期格式输出
    function getUTCTime(second) {
        var d = new Date();

        //转换毫秒
        d.setTime(second * 1000);

        /*
         var year=d.getFullYear();
         var month=d.getMonth()+1;
         var datenum=d.getDate();
         var hour = d.getHours();
         var minute = d.getMinutes();
         var second = d.getSeconds();
         return year+"-"+month+"-"+datenum + " " + hour+":"+minute+":"+second;
         */

        return d.Format("yyyy-MM-dd hh:mm");
    }


    Vue.filter('getLocalTime', function (value) {
        return getUTCTime(value)
    });

</script>
</html>